package com.design.mediator.traffic;

// 中介者接口
interface AirTrafficControl {
    void registerAircraft(Aircraft aircraft);
    void sendWarning(Aircraft aircraft, String message);
}

// 飞机类
class Aircraft {
    private String callsign;
    private AirTrafficControl atc;

    public Aircraft(String callsign, AirTrafficControl atc) {
        this.callsign = callsign;
        this.atc = atc;
        atc.registerAircraft(this);
    }

    public void receiveWarning(String message) {
        System.out.println(callsign + " received warning: " + message);
    }

    public void requestLanding() {
        atc.sendWarning(this, "Requesting landing clearance");
    }

    public void grantLandingClearance() {
        System.out.println(callsign + " granted landing clearance");
    }
}
